<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeLabel"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, themeLayer, options
    url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-world/rest/maps/World";
    new ol.supermap.MapService(url).getMapInfo().then(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [0, 0],
                zoom: 2,
                projection: "EPSG:4326",
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        createTheme();
    });

    function createTheme() {
        var style1, style2, style3;
        style1 = new ol.supermap.ServerTextStyle({
            fontHeight: 4,
            foreColor: new ol.supermap.ServerColor(100, 20, 50),
            sizeFixed: true,
            bold: true

        });
        style2 = new ol.supermap.ServerTextStyle({
            fontHeight: 4,
            foreColor: new ol.supermap.ServerColor(250, 0, 0),
            sizeFixed: true,
            bold: true
        });
        style3 = new ol.supermap.ServerTextStyle({
            fontHeight: 4,
            foreColor: new ol.supermap.ServerColor(93, 95, 255),
            sizeFixed: true,
            bold: true
        });
        var themeLabelItem1, themeLabelItem2, themeLabelItem3, themeLabelItem4, themeLabelItem5, themeLabelItem6;
        themeLabelItem1 = new ol.supermap.ThemeLabelItem({
            start: 0.0,
            end: 7800000,
            style: style1
        });
        themeLabelItem2 = new ol.supermap.ThemeLabelItem({
            start: 7800000,
            end: 15000000,
            style: style2
        });
        themeLabelItem3 = new ol.supermap.ThemeLabelItem({
            start: 15000000,
            end: 30000000,
            style: style3
        });
        themeLabelItem4 = new ol.supermap.ThemeLabelItem({
            start: 0.0,
            end: 55,
            style: style1
        });
        themeLabelItem5 = new ol.supermap.ThemeLabelItem({
            start: 55,
            end: 109,
            style: style2
        });
        themeLabelItem6 = new ol.supermap.ThemeLabelItem({
            start: 109,
            end: 300,
            style: style3
        });

        var themeLabel = new ol.supermap.ThemeLabel({
            matrixCells: [
                [new ol.supermap.LabelThemeCell({
                    themeLabel: new ol.supermap.ThemeLabel({
                        labelExpression: "CAPITAL",
                        rangeExpression: "SmID",
                        numericPrecision: 0,
                        items: [themeLabelItem4, themeLabelItem5, themeLabelItem6]
                    })
                })],
                [new ol.supermap.LabelThemeCell({
                    themeLabel: new ol.supermap.ThemeLabel({
                        labelExpression: "CAP_POP",
                        rangeExpression: "CAP_POP",
                        numericPrecision: 0,
                        items: [themeLabelItem1, themeLabelItem2, themeLabelItem3]
                    })
                })]
            ],
            background: new ol.supermap.ThemeLabelBackground({
                backStyle: new ol.supermap.ServerStyle({
                    fillForeColor: new ol.supermap.ServerColor(179, 209, 193),
                    fillOpaqueRate: 60,
                    lineWidth: 0.1
                }),
                labelBackShape: "RECT"
            })
        });
        var themeParameters = new ol.supermap.ThemeParameters({
            themes: [themeLabel],
            datasetNames: ["Capitals"],
            dataSourceNames: ["World"]
        });

        new ol.supermap.ThemeService(url).getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                themeLayer = new ol.layer.Tile({
                    source: new ol.source.TileSuperMapRest({
                        url: url,
                        noWrap: true,
                        cacheEnabled: false,
                        transparent: true,
                        layersID: result.newResourceID,
                        transparent: true
                    })
                });
                map.addLayer(themeLayer);
            }
        });
    }

</script>
</body>
</html>